# To change this template, choose Tools | Templates
# and open the template in the editor.

#购物车
class Cart
  attr_reader :items
  attr_reader :total_price
  def initialize
    empty!
  end

  def empty!
    @items = []
    @total_price = 0.0
  end
  
  def add_product(product)
    item = @items.find {|i| i.product_id == product.id}
    if item
      item.quantity += 1
    else
      item = LineItem.for_product(product)
      @items << item
    end
    @total_price += product.price
  end

  
end
